﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using System.Data;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;

using DCBH.Bussiness;
using DCBH.Web;
using DCBH.Report.ReportDataset;
using DCBH.Report.Report;

namespace ZX.WebApp.DCBH.Report
{
    public partial class WebForm1 : BasePage
    {
        DCBHReport dcbhReport = new DCBHReport();

        private string strEntity = string.Empty;
        private string strTable = string.Empty;
        private Guid functionID = Guid.Empty; //所属
        private string reportName = string.Empty;
        private string condition = string.Empty;
        private string customCondition = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.UserId == null)
            {
                Response.Redirect("/Error.aspx?message=2&functionId=" + FunctionID);
            }

            strEntity = GetStringFromQueryString("entity", "");
            functionID = GetGuidFromQueryString("functionID");
            condition = GetStringFromQueryString("condition", "");
            customCondition = GetStringFromQueryString("customCondition", "");

            switch (strEntity)
            {
                case "V_BH_InvBalance":
                    RptBHInvBalance(condition, customCondition);
                    break;
                case "V_BH_WorkOrder":
                    RptBHWorkOrder(condition, customCondition);
                    break;
                default:
                    break;
            }
        }

        private void RptBHInvBalance(string condition, string customCondition)
        {
            try
            {
                DataSet ds = new DataSet();
                DataTable dtBHInvBalance = dcbhReport.ReturnBHInvBalance(condition, customCondition);
                if (ds != null)
                {
                    ds.Tables.Add(dtBHInvBalance.Copy());
                    ds.DataSetName = "dsBHInvBalance";
                    ds.Tables[0].TableName = "dtBHInvBalance";

                    rptBHInvBalance ib = new rptBHInvBalance();
                    ib.DataSource = ds;
                    ReportViewer1.Report = ib;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void RptBHWorkOrder(string condition, string customCondition)
        {
            try
            {
                DataSet ds = new DataSet();
                DataTable dtBHWorkOrder = dcbhReport.GetBHWorkOrder(condition, customCondition);
                
                if (ds != null)
                {
                    ds.Tables.Add(dtBHWorkOrder.Copy());
                   
                    ds.DataSetName = "dsBHWorkOrder";
                    ds.Tables[0].TableName = "dtBHWorkOrder";
                    //DataTable datetable = new DataTable("dtBHBOMDetail");
                    //ds.Tables.Add(datetable);
                    DataTable dtBHBOMDetail = dcbhReport.GetBHBomDetail(dtBHWorkOrder.Rows[0]["BOMNo"].ToString());
                    ds.Tables.Add(dtBHBOMDetail.Copy());
                    ds.Tables[1].TableName = "dtBHBOMDetail";

                    rptBHWorkOrder ib = new rptBHWorkOrder();
                    ib.DataSource = ds;
                    ReportViewer1.Report = ib;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}